/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package titanisu.basicMathModule1.LinearEquation;

import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author Balaji
 */
public class QuestionsGeneratorLinearEquation implements titanisu.Modules.baseInterfaces.QuestionsGenerator {

    ArrayList quest = new ArrayList();

    private void setQ(ArrayList arlst) {
        this.quest = arlst;
    }

    public ArrayList getQuest() {
        return quest;
    }

    public void setQuest(ArrayList quest) {
        this.quest = quest;
    }

    public String getQuestions() {
        titanisu.templates.helperClasses.MainHelper mh = new titanisu.templates.helperClasses.MainHelper();
        ArrayList template = mh.getMMLTemplateFor("lesv", 1);
        ArrayList quest = mh.resolveTemplate(template);
        setQ(quest);
        return (String) quest.get(0);
    }

    public void getOptions() {
        String[] options = new String[4];
        Random r = new Random();

        if (quest.size() > 2) {
            options[0] = " <math>  <mfrac>       <mi>" + quest.get(1) + "</mi>  <mi>" + quest.get(2) + "</mi>    </mfrac> </math>  ";
            options[1] = "  <math>  <mfrac>       <mi>" + r.nextInt(30) + "</mi>  <mi>" + r.nextInt(30) + "</mi>    </mfrac> </math>";
            options[2] = " <math>   <mfrac>       <mi>" + r.nextInt(30) + "</mi>  <mi>" + r.nextInt(30) + "</mi>    </mfrac></math> ";
            options[3] = "  <math>  <mfrac>       <mi>" + r.nextInt(30) + "</mi>  <mi>" + r.nextInt(30) + "</mi>    </mfrac></math> ";

        } else {
            r.nextInt(30);
            options[0] = (String) quest.get(1);
            options[1] = r.nextInt(30) + "";
            options[2] = r.nextInt(30) + "";
            options[3] = r.nextInt(30) + "";
        }

    }

    /**
     *
     * @return
     */
    public String getAnswer() {
        String answer = "";
//        titanisu.mathUtil.NumberFetcher nfU = ;
        //mathUtil.NumberFetcher();


        if (quest.size() > 2) {
            int[] an = (new titanisu.mathUtil.NumberFetcher()).simplifyFraction(Integer.parseInt((String) quest.get(1)), Integer.parseInt((String) quest.get(2)));
            answer = " <math>  <mfrac>       <mi>" + quest.get(1) + "</mi>  <mi>" + quest.get(2) + "</mi>    </mfrac> </math>";
        } else {
            answer = " <math>  <mn> " + (String) quest.get(1) + "</mn> </math>";
        }
        return answer;

    }

    @Override
    public ArrayList getAnswers(ArrayList arlst) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList getQuestions(ArrayList arlst) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
